#include "../pch.h"
#include "schema/REFXMLSchemaInfo.h"

namespace BFX
{

REFXMLDocumentType::REFXMLDocumentType(const UniString& strName, const UniString& strPublicId, const UniString& strSystemId, const UniString& strInternalSubset, REFXMLDocument* pDoc)
	: REFXMLLinkedNode(pDoc)
{
	m_strName		 = strName;
	m_strPublicId	= strPublicId;
	m_strSystemId	= strSystemId;
	m_strInternalSubset	= strInternalSubset;
	m_bNamespaces	= true;

	// TODO: IsLoading
}
REFXMLDocumentType::~REFXMLDocumentType()
{
}

// Gets the name of the node.
UniString REFXMLDocumentType::GetName() const
{
	return m_strName;
}
// Gets the name of the current node without the namespace prefix.
UniString REFXMLDocumentType::GetLocalName() const
{
	return GetName();
}

// Gets the type of the current node.
XMLNodeType REFXMLDocumentType::GetNodeType() const
{
	return XMLNodeType_DocumentType;
}

// Gets the collection of XmlEntity nodes declared in the document type declaration.
REFXMLNodeMap* REFXMLDocumentType::GetEntities() const
{
	REFXMLDocumentType* p = const_cast<REFXMLDocumentType*>(this);
	if (p->m_pEntities == NULL)
		p->m_pEntities = new REFXMLNodeMap(p);
	return m_pEntities;
}

// Gets the collection of XmlNotation nodes present in the document type declaration.
REFXMLNodeMap* REFXMLDocumentType::GetNotations() const
{
	REFXMLDocumentType* p = const_cast<REFXMLDocumentType*>(this);
	if (p->m_pNotations == NULL)
		p->m_pNotations = new REFXMLNodeMap(p);
	return m_pNotations;
}

//
// DOM Level 2
//

// Gets the value of the public identifier on the DOCTYPE declaration.
UniString REFXMLDocumentType::GetPublicId() const
{
	return m_strPublicId;
}
// Gets the value of the system identifier on the DOCTYPE declaration.
UniString REFXMLDocumentType::GetSystemId() const
{
	return m_strSystemId;
}
// Gets the entire value of the DTD internal subset on the DOCTYPE declaration.
UniString REFXMLDocumentType::GtInternalSubset() const
{
	return m_strInternalSubset;
}

// Saves the node to the specified XmlWriter.
void REFXMLDocumentType::WriteTo(REFXMLWriter* w) const
{
	w->WriteDocType(m_strName, m_strPublicId, m_strSystemId, m_strInternalSubset);
}
// Saves all the children of the node to the specified XmlWriter.
void REFXMLDocumentType::WriteContentTo(REFXMLWriter* w) const
{
	// NOTE: intentionally do nothing
}

bool REFXMLDocumentType::IsParseWithNamespaces() const
{
	return m_bNamespaces;
}
void REFXMLDocumentType::SetParseWithNamespaces(bool bNamespaces)
{
	m_bNamespaces = bNamespaces;
}

REFXMLSchemaInfo* REFXMLDocumentType::GetDtdSchemaInfo() const
{
	return m_pSchemaInfo;
}
void REFXMLDocumentType::SetDtdSchemaInfo(REFXMLSchemaInfo* pSchemaInfo)
{
	m_pSchemaInfo = pSchemaInfo;
}

}	//	namespace BFX
